// index.js
var app = getApp()
Page({
  data: {
    labelMap:{},
    formData:{
          //basicInfo
    saleName:"",
    doctorName:"",
    hospital: "",
    department:"",
    patientName:"",
    patientGender: "",
    patientAge:"",
    patientPhone:"",
    patientAddress:"",
    bussinessType:"",
    reportMail: true,
    // productInfo
    product:"",
    sampleType:'',
    checkReport:"",
    orderComment:"",
    consult:"",
    // payInfo
    orderPrice:"",
    disCount:true,
    disCountNumber:"",
    payment:"",
    paymentDay:"",
    payComment:"",
    // invoiceInfo
    invoiceMail:"",
    invoiceTitle:"",
    invoiceComment:"",
    },


    active:"0",
    clientList: [],
    calenderShow:false,

    columns:['临床', '入院', '经销', '科研'],
    // yangbenClass:['血液','脑脊液','肺泡灌洗液','唾液','口腔试纸'],
    show: false,
    business: "",
    gender: 0,
    reportMailChecked:true,
    option1: [
      { text: '临床', value: 0 },
      { text: '入院', value: 1 },
      { text: '经销', value: 2 },
      { text: '科研', value: 3 },
    ],
    active:0,
    steps: [
      {
        text: '基本信息',
        inactiveIcon: 'passed',
        activeIcon: 'checked',
      },
      {
        text: '产品信息',
        inactiveIcon: 'passed',
        activeIcon: 'checked',
      },
      {
        text: '支付信息',
        inactiveIcon: 'passed',
        activeIcon: 'checked',
      },
      {
        text: '发票信息',
        inactiveIcon: 'passed',
        activeIcon: 'checked',
      }
    ],
  },

  submit(event){
    console.log("提交");
    console.log(this.data.labelMap)
    this.setData({
      "formData.saleName":this.data.saleName,
      "formData.doctorName":this.data.doctorName,
      "formData.hospital":this.data.hospital,
      "formData.department":this.data.department,
      "formData.patientName":this.data.patientName,
      "formData.patientGender":this.data.patientGender,
      "formData.patientAge":this.data.patientAge,
      "formData.patientPhone":this.data.patientPhone,
      "formData.patientAddress":this.data.patientAddress,
      "formData.bussinessType":this.data.bussinessType,
      "formData.reportMail":this.data.reportMail,
    })
    console.log(this.data.formData)
    // wx.redirectTo({
    //   url: '/pages/submit_success/submit_success',
    // });
  },

  onLoad(){
    this.setData({
      labelMap:app.labelMap
    })
  },

  genderChange(e){
    this.setData({
      "patientGender":e.detail
    })
  },

  showPopup(){
    this.setData({
      "show": true
    })
  },

  onCancel(){
    this.setData({
      "show": false
    })
  },

  onConfirm(event){
    this.setData({
      "show": false,
      "business": event.detail.value
    })
    this.setData({
      active: this.data.active+1
    })
    console.log(this.data.active)
  },
  onReportMailChange({ detail }) {
    // 需要手动对 checked 状态进行更新
    this.setData({ reportMailChecked: detail });
  },
  sampleChange(event) {
    console.log(event.detail)
    this.setData({
      sample: event.detail,// 更新sample的值
    })
   console.log(this.data.sample)
  },
  clickBack(event){
    this.setData({
      active:this.data.active-1
    })
  },
  afterRead(event) {
    const { file } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      url: '', // 仅为示例，非真实的接口地址
      filePath: file.url,
      name: 'file',
      formData: { user: 'test' },
      success(res) {
        // 上传完成需要更新 fileList
        const { fileList = [] } = this.data;
        fileList.push({ ...file, url: res.data });
        this.setData({ fileList });
      },
    });
  },
  onDisplay() {
    this.setData({ calenderShow: true });
  },
  onClose() {
    this.setData({ calenderShow: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getMonth() + 1}/${date.getDate()}`;
  },
  calenderConfirm(event) {
    this.setData({
      calenderShow: false,
      date: this.formatDate(event.detail),
    });
  }
});



